﻿using System;
using System.Drawing;
using Newtonsoft.Json.Linq;
using xbmc_json_async.System;

using System.Collections.Generic;
using xbmc_json_async.Utilities;

namespace xbmc_json_async.Media
{
    
    public class Episode : xbmc_json_async.Types.Video.Details.Episode
    {
        private JObject mJObject;

        /// <summary>
        /// Gets the internal property object.
        /// </summary>
        public JObject InternalPropertyObject
        {
            get
            {
                return mJObject;
            }
            private set
            {
                mJObject = (JObject)value;
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Episode"/> class.
        /// </summary>
        public Episode() { }

        public Episode(int id, string file, string label, string thumbnail, string fanart, string plot, string show,
               int episodeNumber, int season, int year)
        {
            throw new NotImplementedException("Use empty constructor, and build from JsonObject");
            /*Id = id;
            File = file;
            Label = label;
            Thumbnail = thumbnail;
            Fanart = fanart;
            Plot = plot;
            Show = show;
            EpisodeNumber = episodeNumber;
            Season = season;
            Year = year;*/
        }

        public static Episode FromJsonObject(JObject item)
        {
            var episode = new Episode();
            episode.director = XHelpers.Jval(item, "director");
            episode.episode = XHelpers.JvalInt(item, "episode");
            episode.episodeid = XHelpers.JvalInt(item, "episodeid");
            episode.fanart = XHelpers.Jval(item, "fanart");
            episode.file = XHelpers.Jval(item, "file");
            episode.firstaired = XHelpers.Jval(item, "firstaired");
            episode.label = XHelpers.Jval(item, "label");
            episode.lastplayed = XHelpers.Jval(item, "lastplayed");
            episode.originaltitle = XHelpers.Jval(item, "originaltitle");
            episode.playcount = XHelpers.JvalInt(item, "playcount");
            episode.plot = XHelpers.Jval(item, "plot");
            episode.productioncode = XHelpers.Jval(item, "productioncode");
            episode.rating = XHelpers.JValDouble(item, "rating");
            episode.runtime = XHelpers.Jval(item, "runtime");
            episode.season = XHelpers.JvalInt(item, "season");
            episode.showid = XHelpers.JvalInt(item, "showid");
            episode.showtitle = XHelpers.Jval(item, "showtitle");
            episode.thumbnail = XHelpers.Jval(item, "thumbnail");
            episode.title = XHelpers.Jval(item, "title");
            episode.votes = XHelpers.Jval(item, "votes");
            episode.writer = XHelpers.Jval(item, "writer");

            /*
            Injector injector = new Injector();
            var vObj = (object)episode;
            episode = (Episode)injector.FillObject(vObj, (object)item);
            */
            return episode;
        }

        /*
        public static Episode FromPlayListItem(PlaylistItem item)
        {
            Episode e = new Episode(
                item._id,
                item.File,
                item.Label,
                item.Thumbnail,
                item.Thumbnail,
                item.Plot,
                item.Show,
                item.EpisodeNum,
                item.Season,
                item.Year
                );
            return e;
        }
        */

        public override string ToString()
        {
            return string.Empty;

            //if (Label != "")
            //    return Label;
            //else
            //    return File;
        }
    }
}